// FiveWin Visual IDE
// (c) FiveTech 1993-2008

#include "FiveWin.ch"
#include "Visual.ch"
#include "splitter.Ch"
#include "xbrowse.ch"

memvar oIDE

#define VFW_VERSION  "Visual FiveWin for Harbour/xHarbour"

#define SIZE_RESTORED   0
#define SIZE_MINIMIZED  1
#define SIZE_MAXIMIZED  2

//----------------------------------------------------------------------------//

function Main( cFileName )

   local oWnd
   local hRichDLL := LoadLibrary( "riched20.dll" )  // Richedit support

   public oIDE

   // To trace calls for FWH
   // __TRACEPRGCALLS( .t. )
   // HB_TRACELEVEL( 5 )
   // hb_tracestate( 1 )

   MsgLogo( "FW" )           // "FW" is the name of a resource bitmap

   SetResDebug( .t. )

   SET HELPFILE TO "docs\Visual.hlp"

   oIDE = TVisualIDE():New()

   oIDE:Activate( cFileName )

   // CheckRes()
   FreeLibrary( hRichDLL )

return nil

//----------------------------------------------------------------------------//

CLASS TVisualIDE

   DATA   oWndMain           // Main window of the application
   DATA   oInspector         // Object Inspector window
   DATA   oWndCode           // Source code editing window
   DATA   oToolBar           // ToolBar window
   DATA   oProject           // Project window
	 DATA		oGeneralOpt			 	 // General Compiler Options
	 DATA 	oBar1							 // ButtonBar //daniel
	 DATA   oBar2							 // ButtonBar Poject //daniel

   DATA   oActiveForm        // Current focused edited form

   DATA   oMruDbfs
   DATA   oMruPrgs           // MRU-Programs
   DATA   oMruPrjs           // MRU-Projects
   DATA   oMruRes

   DATA   oItForms           // MenuItem that holds all the active edited forms

   DATA   cArguments         // Application Execution arguments

   DATA   oHand              // Cursor Hand

   DATA   oWndActive         // Form or Source code editor

   DATA   oSplitter          // middle Splitter

   DATA   oToolBar           // right side toolbar
   DATA   nToolBar           // Currently selected toolbar category

   DATA   cToolControl       // temporarely holds the tool control name (its tooltip)
                             // to place on the form

   
   DATA   nLinker INIT 1
   DATA   lNew		INIT .t.	// daniel, Project status, new or old


   METHOD New() CONSTRUCTOR

   METHOD Activate( cFileName )

   METHOD BuildBars()
   METHOD BuildMenu()

   METHOD Close()


   METHOD End() INLINE ::oWndMain:End()

   METHOD LoadForm( cFileName )

   METHOD NewForm()
   METHOD NewProgram()

   METHOD Open()
   METHOD OpenForm( cFormFile )
   METHOD OpenProgram( cPrgName )   
   METHOD OpenFiles( aFiles )
   
   //METHOD Option( nType, cIniFile )		//daniel

   METHOD Arguments()

   METHOD MainReSize( nMode )

   METHOD Save()
   METHOD SaveAs()

   METHOD SelToolBarBtn( oBtn )   
   METHOD SetToolBar( nToolBar )  // Set the toolbar group of buttons

ENDCLASS

//----------------------------------------------------------------------------//

METHOD New() CLASS TVisualIDE

   local oFont, oTabs

   ::cArguments = ""
	 ::oGeneralOpt = TOptionsComp():New( "visual.ini", MAIN )
	 ::oGeneralOpt:DefaultAll()
	 ::oGeneralOpt:CompilerIni()


   oIDE = Self

   DEFINE FONT oFont NAME "Ms Sans Serif" SIZE 0, -8

   DEFINE WINDOW ::oWndMain TITLE VFW_VERSION  ;
      MENU ::BuildMenu() FROM 0, 0 TO 7, 120 ;
      ICON "FiveWin"

   ::oWndMain:aMinMaxInfo = { GetSysMetrics() + 7,;
                              If( ! IsAppThemed(), 103, 110 ) * DispFontPerSize(),;
                              -4, -4, 400, 118,;
                              GetSysMetrics() + 7,;
                              If( ! IsAppThemed(), 103, 110 ) * DispFontPerSize() }
   ::oWndMain:bReSized    = { | nMode, nWidth, nHeight | ;
                              ::MainResize( nMode ) }

   DEFINE CURSOR ::oHand HAND

   ::BuildBars()
	 
   ::oInspector  = TInspector():New()
   ::oWndCode    = TWndCode():New()
   ::oProject    = TWndPrj():New()

   ::oWndMain:SetText( VFW_VERSION + " - " + ::oProject:cName )
		

   ::oProject:Hide()
   ::NewForm()
return Self

//----------------------------------------------------------------------------//

METHOD Activate( cFileName ) CLASS TVisualIDE

   local cExt, oThis := Self

   if ! Empty( cFileName )
      ::OpenFiles( { cFileName } )
   endif

   ACTIVATE WINDOW ::oWndMain MAXIMIZED ;
      VALID If( MsgYesNo( "Want to end ?" ),( if( !::lNew, ::Save(), ), .t. ) , .f. ) ;
      ON DROPFILES ::OpenFiles( aFiles ) ;
      ON RESIZE ::oSplitter:AdjClient() //;      ON INIT ( oThis:oActiveForm:SetFocus() ) //daniel

   ::oHand:End() // Release cursor hand

return nil

//----------------------------------------------------------------------------//

METHOD BuildBars() CLASS TVisualIDE

   local oPanel1 := TPanel():New( 0, 0, 0, 363, ::oWndMain )
   local oPanel2 := TPanel():New( 0, 368, 0, 200, ::oWndMain )
   local oBar1, oBar2, oTabs, oBtnForms, n

   DEFINE BUTTONBAR ::oBar1 OF oPanel1 2007 SIZE 30, 30
   ::oBar1:bRClicked = { || nil }
   ::oBar1:bLClicked = { || nil }

   DEFINE BUTTON RESOURCE "Exit" NOBORDER OF ::oBar1 ;
      ACTION ::oWndMain:End() TOOLTIP "Exit" ;
      MESSAGE "Exit from IDE"

   DEFINE BUTTON RESOURCE "Open" NOBORDER OF ::oBar1 ;
      TOOLTIP "Open" ;
      ACTION  ::Open()

   DEFINE BUTTON RESOURCE "Save" NOBORDER OF ::oBar1 ;
      TOOLTIP "Save" ;
      MESSAGE "Save current project to disk" ;
      ACTION  ::Save() //when ::oProject != NIL

   DEFINE BUTTON RESOURCE "newform" NOBORDER OF ::oBar1 GROUP ;
      TOOLTIP "New form" ;
      MESSAGE "Creates a new form" ACTION ::NewForm() //when ::oProject != NIL

   DEFINE BUTTON RESOURCE "newprg" NOBORDER OF ::oBar1 ;
      TOOLTIP "New program" ;
      MESSAGE "Creates a new prg" ACTION ::NewProgram() //when ::oProject != NIL

   DEFINE BUTTON RESOURCE "Cut" NOBORDER OF ::oBar1 GROUP ;
      TOOLTIP "Cut" ;
      MESSAGE "Cut to Clipboard" ACTION MsgInfo( "Cut" ) //when ::oProject != NIL 

   DEFINE BUTTON RESOURCE "Copy" NOBORDER OF ::oBar1 ;
      TOOLTIP "Copy" ;
      MESSAGE "Copy to Clipboard" ACTION ::oWndMain:Copy() //when ::oProject != NIL

   DEFINE BUTTON RESOURCE "Paste" NOBORDER OF ::oBar1 ;
      TOOLTIP "Paste" ACTION ::oWndMain:Paste() //when ::oProject != NIL

   DEFINE BUTTON RESOURCE "Delete" NOBORDER OF ::oBar1 ;
      TOOLTIP "Delete" ACTION ::oWndMain:Delete() //when ::oProject != NIL

   DEFINE BUTTON RESOURCE "UnDo" NOBORDER OF ::oBar1 GROUP ;
      TOOLTIP "UnDo" ACTION ::UnDo() //when ::oProject != NIL

   DEFINE BUTTON RESOURCE "ReDo" NOBORDER OF ::oBar1 ;
      TOOLTIP "ReDo" ACTION ::ReDo() //when ::oProject != NIL

   DEFINE BUTTONBAR ::oBar2 OF oPanel1 2007 SIZE 30, 30 BOTTOM 
   ::oBar2:bLClicked = { || nil }
   ::oBar2:bRClicked = { || nil }
   oPanel1:oTop = ::oBar1
   oPanel1:oBottom = ::oBar2
	
	 //::oBar2:disable()

   DEFINE BUTTON RESOURCE "project" NOBORDER OF ::oBar2 ;
      TOOLTIP "Project manager" ;
      ACTION ( ::oProject:Show(), ::oProject:Restore(), ::oProject:SetFocus() )

   DEFINE BUTTON oBtnForms RESOURCE "Form" NOBORDER OF ::oBar2 GROUP ;
      TOOLTIP "Forms" ACTION oBtnForms:ShowPopup() MENU ::oItForms:bAction 

   DEFINE BUTTON RESOURCE "Source" NOBORDER OF ::oBar2 ;
      TOOLTIP "Source editor" ACTION ::oWndCode:SetFocus() 

   DEFINE BUTTON RESOURCE "Setup" NOBORDER OF ::oBar2 GROUP ;
      TOOLTIP "Project setup" ACTION ::oProject:oProjectOpt:Option()

   DEFINE BUTTON RESOURCE "Build" NOBORDER OF ::oBar2 ;
      TOOLTIP "Build" ACTION ::oProject:Build() 

   DEFINE BUTTON RESOURCE "Exec" NOBORDER OF ::oBar2 ;
      TOOLTIP "Run" ACTION ::oProject:Run( ::cArguments ) 

   DEFINE BUTTON RESOURCE "Debug" NOBORDER OF ::oBar2 TOOLTIP "Debug" ;
      ACTION ::oProject:Debug( ::cArguments ) 

   DEFINE BUTTON RESOURCE "About" NOBORDER OF ::oBar2 GROUP ;
      TOOLTIP "Info" ;
      ACTION MsgLogo( "fw" ) 

   AEval( ::oBar1:aControls, { | o | o:oCursor := ::oHand } )
   AEval( ::oBar2:aControls, { | o | o:oCursor := ::oHand } )

   DEFINE BUTTONBAR ::oToolBar OF oPanel2 SIZE 45, 45 2007
   ::oToolBar:bLClicked = { || nil }
   ::oToolBar:bRClicked = { || nil }
   
   DEFINE BUTTON OF ::oToolBar RESOURCE "arrow" ;
      TOOLTIP "Pointer" ACTION ::SelToolBarBtn( this ) PRESSED   

   for n = 1 to 13
      DEFINE BUTTON OF ::oToolBar ACTION ::SelToolBarBtn( this )

      ::oToolBar:aControls[ n + 1 ]:bWhen = GenNonEmptyToolTipBlock( ::oToolBar:aControls[ n + 1 ] )
   next   

   oPanel2:oTop = ::oToolBar
   
   ::SetToolBar( 1 )
   //::oToolBar:disable()

   @ 8, 0 TABS oTabs PROMPTS "&Standard", "&Additional", "3rd &party", "&Database",;
        "D&ialogs", "In&ternet", "Active&X" OF oPanel2 ;
        ACTION ::SetToolBar( nOption ) 

   oPanel2:oBottom = oTabs

   @ 0, 363 SPLITTER ::oSplitter ;
            VERTICAL ;
            PREVIOUS CONTROLS oPanel1 ;
            HINDS CONTROLS oPanel2 ;
            LEFT MARGIN 90 ;
            RIGHT MARGIN 180 ;
            SIZE 4, nil  PIXEL ;
            OF ::oWndMain ;
            _3DLOOK ;
            UPDATE

return nil

//----------------------------------------------------------------------------//

METHOD BuildMenu() CLASS TVisualIDE

   local oMenu
   local cTemp

   MENU oMenu 2007
      MENUITEM "&Projects"
      MENU
        MENUITEM "&New..."  MESSAGE "Creates a new project" RESOURCE "NewProj";
        	action( ::oInspector  := TInspector():New(),;
   								::oWndCode    := TWndCode():New(),;
   								::oProject    := TWndPrj():New(),;
   								::oWndMain:SetText( VFW_VERSION + " - " + ::oProject:cName ),;
									::oProject:Hide(),;
   								::NewForm() ,;
			            ::oBar2:enable(),;
           				::oToolBar:enable() )
   								

        MENUITEM "&Open..." MESSAGE "Open an existing project" RESOURCE "Open"
        MENU
           MENUITEM "&Search... " RESOURCE "search" ;
              ACTION ( if ( !empty( cTemp:=cGetFile( "VFWH Project file (*.fpr) |*.fpr|",;
                               "Select a VFWH Project to open" ) ), ::Open( cTemp ),) )
           MRU ::oMruPrjs INI "Visual.ini" SECTION "MRU-Projects" ;
              MESSAGE "Open this project" ACTION ::open( cMruItem ) 
        ENDMENU

        MENUITEM "&Save..."      ACTION ::Save() RESOURCE "Save" //when ::oProject != NIL
        MENUITEM "Save &as..."   ACTION ::SaveAs() //when ::oProject != NIL
        MENUITEM "Close Project" ACTION ::Close() //when ::oProject != NIL
        SEPARATOR

        MENUITEM "New &Form..."     ACTION ::NewForm()     RESOURCE "newform" //when ::oProject != NIL
        MENUITEM "New &Program..."  ACTION ::NewProgram()  RESOURCE "newprg"  //when ::oProject != NIL
        MENUITEM "Open F&orm..."    ACTION ::OpenForm()    RESOURCE "form" 		//when ::oProject != NIL
        MENUITEM "Open P&rogram..." ACTION ::OpenProgram() RESOURCE "source" 	//when ::oProject != NIL
        SEPARATOR

        MENUITEM "&Setup..."     MESSAGE "Setup the current project" ;
           ACTION ::oProject:oProjectOpt:Option() RESOURCE "Setup" //when ::oProject != NIL
        MENUITEM "&Build..."     MESSAGE "Builds the current project" ;
           ACTION ::oProject:Build() RESOURCE "Build" //when ::oProject != NIL
        MENUITEM "&Run..."       MESSAGE "Executes the current project" ;
           ACTION ::oProject:Run( ::cArguments ) RESOURCE "Exec" //when ::oProject != NIL
        MENUITEM "&Debug..."       MESSAGE "Debugs the current project" ;
           ACTION ::oProject:Debug( ::cArguments ) RESOURCE "Debug" when ::oProject != NIL
        MENUITEM "&Arguments..." MESSAGE "Current project run arguments" ;
           ACTION ::Arguments() //when ::oProject != NIL

        SEPARATOR
        MENUITEM "&Print..." RESOURCE "Print"
        MENUITEM "Printer &Setup..." ACTION PrinterSetup()

        SEPARATOR
        MENUITEM "E&xit..." ACTION ::oWndMain:End() ;
           MESSAGE "Exit VFWH IDE" RESOURCE "exit"
      ENDMENU

      oMenu:AddEdit()

      MENUITEM "&Databases"
      MENU
         MENUITEM "&Use DataBase..." ACTION DbfOpen(,, ::oMruDbfs ) ;
            MESSAGE "Open a DataBase"

         MENUITEM "&Create DataBase..."  ACTION DbfNew( ::oMruDbfs ) ;
            MESSAGE "Create a new DataBase"

         MRU ::oMruDbfs INI "Visual.ini" SECTION "MRU-DataBases" ;
            MESSAGE "Browse this DataBase" ;
            ACTION DbfOpen( cMruItem,, ::oMruDbfs )

      ENDMENU

      MenuAddTools( "visual.ini" )

      MENUITEM "&Views"
      MENU
         MENUITEM "&Object Inspector..." RESOURCE "properties" ;
            ACTION ( ::oInspector:Show(), ::oInspector:SetFocus() ) ;
            MESSAGE "Shows the Object Inspector" when ::oInspector != NIL

         MENUITEM "&Project Manager..." RESOURCE "project" ;
            ACTION ( ::oProject:Show(), ::oProject:Restore(),;
                     ::oProject:SetFocus() ) ;
            MESSAGE "Shows the Project Manager" when ::oProject != NIL

         MENUITEM "&Source code editor..." RESOURCE "source" ;
            ACTION ( ::oWndCode:Show(), ::oWndCode:SetFocus() ) ;
            MESSAGE "Shows the source code editor" when ::oWndCode != NIL

         SEPARATOR

         MENUITEM ::oItForms PROMPT "&Forms"
         MENU 
         ENDMENU
      ENDMENU
      
     	MENUITEM "&General Option" ;//RESOURCE "option";
   		ACTION ( ::oGeneralOpt:Option() )
   
      oMenu:AddHelp( { || MsgLogo( "fw" ) } )

   ENDMENU

return oMenu

//----------------------------------------------------------------------------//

METHOD Close() CLASS TVisualIDE

   if ::oProject != nil
      ::oProject:Close()
      ::oProject = nil
      ::oWndCode:Close()
      ::oWndCode = nil  
      ::oInspector:close()
      ::oInspector = nil
      ::oWndMain:SetText( VFW_VERSION )
   		::oBar2:disable()			//daniel
   		::oToolBar:disable()	//daniel
   endif

return nil

//----------------------------------------------------------------------------//

METHOD LoadForm( cFileName, lShow ) CLASS TVisualIde

   local oForm := TDesigner():New(), oItem
   default lShow := .t.


   oForm:LoadFile( cFileName )

   ::oItForms:bAction:Add( oItem := TMenuItem():New( oForm:cVarName,,,,;
                           { || oForm:Show(), oForm:SetFocus() },, "form" ) )
     
	   ::oActiveForm = oForm
	   ::oInspector:SetForm( oForm )
	   oForm:Show()
	   oForm:SetFocus()
 			   

return oForm

//----------------------------------------------------------------------------//

METHOD NewForm() CLASS TVisualIDE

   local oForm := ::oProject:NewForm()

   ::oItForms:bAction:Add( TMenuItem():New( oForm:cVarName,,,,;
                           { || oForm:Show(), oForm:SetFocus() },, "form" ) )
   ::oActiveForm = oForm
   ::oInspector:SetForm( oForm )
   oForm:Show()
   oForm:SetFocus()

return nil

//----------------------------------------------------------------------------//

METHOD NewProgram() CLASS TVisualIDE

   local oForm := ::oWndCode:AddPage( "noname.prg",;
      '#include "FiveWin.ch"' + CRLF + CRLF + ;
      "//------------------------------------------------------" + ;
      "---------------------//" + CRLF + CRLF + ;
      "function Noname()" + CRLF + CRLF + CRLF + CRLF + "return nil" + CRLF + CRLF + ;
      "//------------------------------------------------------" + ;
      "---------------------//" )

   AAdd( ::oProject:aPrograms, { "noname.prg", "" } )
   ::oProject:oBrw:Refresh()

   ::oWndCode:SetFocus()

return nil

//----------------------------------------------------------------------------//

METHOD Open( cFileName ) CLASS TVisualIDE

   local oIni, n := 1, cForm, oForm

   local nFileType 

	 default cFileName := cGetFile( "VFWH Project file (*.fpr) |*.fpr|" + ;
                                "Program file (*.prg) |*.prg|" + ;
                                "Header file (*.ch) |*.ch|" + ;
                                "VFWH form (*.frm) |*.frm|" + ;
                                "Open as ASCII file (*.*) |*.*|",;
                                "Select a file to open" )

	 nFileType := nGetFileFilter()

   if Empty( cFileName )
      return nil
   endif

   if ! File( cFileName )
      MsgAlert( "File " + cFileName + " not found!" )
      return nil
   endif

   do case
      case nFileType == 1 // Project

					if !::lNew
           ::Save()
          endif
					 ::Close()
           ::oInspector = TInspector():New()
           ::oWndCode   = TWndCode():New()
           ::oProject   = TWndPrj():open( cFileName )

           oIni = TIni():New( cFileName )

           if ! Empty( cForm := oIni:Get( "FORMS", AllTrim( Str( n++ ) ) ) )
              oForm := ::LoadForm( cForm )
              AAdd( ::oProject:aForms, oForm )
           endif

           while ! Empty( cForm := oIni:Get( "FORMS", AllTrim( Str( n++ ) ) ) )
              oForm := ::LoadForm( cForm, .f. )
              AAdd( ::oProject:aForms, oForm )
           end

           ::oWndMain:SetText( VFW_VERSION + " - " + cFileName )
           ::oBar2:enable()
           ::oToolBar:enable()

      case nFileType == 2 .or. nFileType == 3 .or. ;
           nFileType == 5 // Program, header file or ASCII file
           ::oWndCode:AddPage( cFileName, MemoRead( cFileName ) )

      case nFileType == 4 // Form
           ::LoadForm( cFileName )

   endcase

return nil

//----------------------------------------------------------------------------//

METHOD OpenFiles( aFiles ) CLASS TVisualIDE

   local cExt, n

   ::oWndMain:Maximize()      // restore main window

   for n = 1 to Len( aFiles )
      cExt = Upper( Right( aFiles[ n ], 3 ) )

      do case
         case cExt == "PRG" .or. cExt == ".CH"
              PrgOpen( aFiles[ n ], ::oMruPrgs )

         case cExt == "DBF"
              DbfOpen( aFiles[ n ],, ::oMruDbfs )
      endcase
   next

return nil

//----------------------------------------------------------------------------//

METHOD OpenForm( cFrmName ) CLASS TVisualIDE

   local oForm

   DEFAULT cFrmName := cGetFile( "VFWH Form ( *.frm ) |*.ffm|",;
                                 "Select a Form",, "forms" )

   if Empty( cFrmName ) 
      return nil
   endif   
   
   if ! File( cFrmName )
      MsgInfo( "I can't find that file!" )
      return nil
   endif

   oForm = ::oProject:OpenForm( cFrmName )
   ::oActiveForm = oForm
   ::oInspector:SetForm( oForm )

   ::oItForms:bAction:Add( TMenuItem():New( oForm:cVarName,,,,;
                           { || oForm:Show(), oForm:SetFocus() } ) )

return nil

//----------------------------------------------------------------------------//

METHOD OpenProgram( cPrgName ) CLASS TVisualIDE

   DEFAULT cPrgName := cGetFile( "Program( *.prg ) | *.prg",;
                                 "Select a PRG, CH or C", "*.prg", "programs" )

   if Empty( cPrgName )
      return nil
   endif   

   if ! File( cPrgName )
      MsgInfo( "I can't find that file!" )
      return nil
   endif

   ::oWndCode:AddPage( cPrgName, MemoRead( cPrgName ) )

   AAdd( ::oProject:aPrograms, { cPrgName, "" } )
   ::oProject:oBrw:Refresh()

   ::oWndCode:SetFocus()

return nil

//----------------------------------------------------------------------------//

METHOD Arguments() CLASS TVisualIDE

   local oDlg
   local cArgs := PadR( ::cArguments, 128 )

   DEFINE DIALOG oDlg RESOURCE "Arguments"

   REDEFINE GET cArgs ID 110 OF oDlg

   REDEFINE BUTTON ID IDOK OF oDlg ;
      ACTION ::cArguments := RTrim( cArgs ), oDlg:End()

   ACTIVATE DIALOG oDlg CENTERED

return nil

//----------------------------------------------------------------------------//

METHOD MainResize( nMode ) CLASS TVisualIDE

   DEFAULT nMode := SIZE_RESTORED

   do case
      case nMode == SIZE_MINIMIZED
           ::oInspector:Hide()
           ::oWndCode:Hide()
           ::oToolBar:Hide()
           ::oProject:Hide()

      case nMode == SIZE_MAXIMIZED
           ::oInspector:Show()
           ::oWndCode:Show()
           ::oToolBar:Show()

      case nMode == SIZE_RESTORED
           ::oInspector:Show()
           ::oWndCode:Show()
           ::oToolBar:Show()
   endcase

return nil

//----------------------------------------------------------------------------//

METHOD Save() CLASS TVisualIDE
local cFolder, cName, cPath, cFile


   if ::oProject != nil
   
   	if ::lNew
   	 if ::SaveAs()
	   	 ::oProject:oProjectOpt := TOptionsComp():New( ::oProject:cName, PROJECT )
		   cFolder := trim( lower( cGetFolder( ::oProject:cName, cFileNoPath( ::oProject:cName ) ) ) )
		   cPath := left( cFolder , len( cFolder ) -1 )
		   ::oProject:oProjectOpt:CompilerIni()
		   ::oProject:oProjectOpt:cPrjMain 		:= cPath
		   ::oProject:oProjectOpt:cPrjOutPut 	:= cPath
		   ::oProject:oProjectOpt:cPrjRes 		:= cPath
		   ::oProject:oProjectOpt:cPrjSource 	:= cPath
		   ::oProject:oProjectOpt:cPrjObj 		:= cPath
		   ::oProject:oProjectOpt:Option()   		
		   ::oProject:Save()
		   ::oMruPrjs:Save( ::oProject:cName )
	   		::lNew := .f.
	   endif
   	else
	   ::oProject:Save()
	   ::oMruPrjs:Save( ::oProject:cName )
  	 ::lNew := .f.
  	 
	  endif
	  
   endif
   
	 
return nil

//----------------------------------------------------------------------------//

METHOD SaveAs() CLASS TVisualIDE
local cName
   
   cName = cGetFile( "*.fpr", "Select a project name",,::oGeneralopt:cPrjMain )
   if !empty( cName )
   	if lower( right( cName, 4 ) ) != ".fpr"
   		cName += ".fpr"
   	endif
   endif
	 if File( cName )
	    if !  MsgYesNo( cName + " already exists on disk" + CRLF + ;
                      "Do you want to overwrite it ?" )
         		return .f.
      endif
   		::lNew := .f.
   endif
   if !empty( cName )
   	::oProject:cName := cName
   	::oWndMain:SetText( VFW_VERSION + " - " + ::oProject:cName )
   	if !::lNew
   		::Save()
   	endif
   	::lNew := .f.
   else
   	return .f.
   endif

return .t.

//----------------------------------------------------------------------------//

METHOD SelToolBarBtn( oBtn ) CLASS TVisualIde

   local n

   for n = 1 to Len( ::oToolBar:aControls )
      if ! oBtn == ::oToolBar:aControls[ n ] .and. ;
         ::oToolBar:aControls[ n ]:lPressed
         ::oToolBar:aControls[ n ]:lPressed = .F.
         ::oToolBar:aControls[ n ]:Refresh()
      endif
   next

   if ! oBtn:lPressed
      oBtn:lPressed = .t.
      oBtn:Refresh()
      ::cToolControl = oBtn:cToolTip
   endif

return nil

//----------------------------------------------------------------------------//

METHOD SetToolBar( nToolBar ) CLASS TVisualIde

   local n, oBtn
   local aToolBars := { ;
      { { "label", "Label" }, { "button", "Button" }, { "edit", "Get" }, { "memo", "Get multiline" }, { "check", "CheckBox" }, { "radio", "RadioButton" }, { "listbox", "ListBox" }, { "combobox", "ComboBox" }, { "hscroll", "Horizontal scroll" }, { "vscroll", "Vertical scroll" }, { "group", "Group" }, { "progress", "Progress bar" }, { "slider", "Slider" } },;
      { { "menu", "Pulldown menu" }, { "bitmap", "Bitmap" }, { "image", "Image" }, { "folder", "Folder" }, { "treeview", "TreeView" }, { "tabs", "Tabs" }, { "meter", "Meter" }, { "msgbar", "MsgBar" }, { "icon", "Icon" }, { "panel", "Panel" }, { "btnbmp", "TBtnBmp" } },;
      {},;
      {},;
      {},;
      {},;
      { { "explorer", "Shell Explorer" } } }

   if ::nToolBar == nil .or. nToolBar != ::nToolBar
   
      ::nToolBar = nToolBar
   
      ::oToolBar:aControls[ 1 ]:lPressed = .T.
      ::oToolBar:aControls[ 1 ]:Refresh()
   
      for n = 2 to Len( ::oToolBar:aControls )
          oBtn = ::oToolBar:aControls[ n ]
          oBtn:FreeBitmaps()
          oBtn:cToolTip = nil
          oBtn:lPressed = .F.
          oBtn:Refresh()
      next     
      
      for n = 1 to Len( aToolBars[ nToolBar ] ) 
          oBtn = ::oToolBar:aControls[ n + 1 ]
          oBtn:LoadBitmaps( aToolBars[ nToolBar ][ n ][ 1 ] )
          oBtn:cToolTip = aToolBars[ nToolBar ][ n ][ 2 ]
      next
   
      ::oToolBar:AEvalWhen()
   endif

return nil

//----------------------------------------------------------------------------//


function GenNonEmptyToolTipBlock( oBtn )

return { || ! Empty( oBtn:cToolTip ) }




Function TextDialog( cText )
	local oDlg, oGet
	local cOldText := cText
	cText := if( !empty( cText ), padR( cText, 128 ), space( 128 ) )
	
	DEFINE DIALOG oDlg RESOURCE "TextDialog" 
	
	REDEFINE GET oGet VAR cText ID ID_GETTEXTDIALOG 
	
	ACTIVATE DIALOG oDlg CENTERED
	
  IF oDlg:nResult == ID_CANCEL
   cText := cOldText
  ENDIF
	
return cText

//-------------------------------------------


#ifndef __XHARBOUR__
function IsDirectory( cPath )
local nFind			
local cSubDir:="", ;
			cArc := ""
			
local aDir := {}

cArc := cFile( cPath )
cSubDir := cGetFolder( cPath, cArc )

aDir := Directory( cSubDir,"D" )
nFind := AScan( aDir, {| cFile | lower( cFile[ 1 ] ) == lower( cArc ) } )

return if (nFind > 0, .t., .f. )

function CurDirx()
return CurDrive()+":\"+CurDir( ) + "\"
#ENDIF

function cGetFolder( cPath, cArc )
local n, ;
			nOcurrence:=0
local cDir, cSubDir

	cSubDir := substr( cPath, 1, at(cArc, cPath )-1 )

return cSubDir

function cFile( cPath )
local n, nOcurrence:= 0
local cArc

	if !file( cPath )
		cPath := trim( cPath ) + "\"
	endif

	for n = 1 to len( alltrim( cPath ) )
		if ( substr( cPath, n, 1 ) = "\", nOcurrence++,)
	next
	
	cArc := strtoken( cPath, nOcurrence, "\" )

return cArc


function cFileNoPath( cName )
local nLen:= 0
local n 
local cFile := cName

	for n = len( alltrim( cName ) ) to 1 step -1
		if substr( cName, n, 1 ) != "\"
			nLen++
		else
			n = 1
		endif
	next
	
	cFile := substr( cName,  len( cName ) - nLen + 1, len( cName ) )

return cFile
